<?php
//------------------------------------------------------------ Contraintes d'accès de la page

	// on vérifie que cette page est appelée à partir de l'index et que l'utilisateur a le droit de consultation
	if(isset($_SESSION) && ($GLOBALS['USER']['level'] >= 2 || $GLOBALS['USER']['admin'])){
	
		// l'identifiant de la donnée à supprimer est indiqué par un entier
		if(isset($_GET['id']) && numericInt($_GET['id'])){
		
			$nb_semis = valueExists((int)$_GET['id'], "CODESEMIS", "semis", $connexion);
			
			if($nb_semis == 1){ // le sachet de graines à afficher existe et son identifiant est unique
	
?>
<?php
/********************************* Règles :

	- id doit désigner un seul semis
	- Le semis doit exister dans la BDD

*****************************************/

	$semis = array(); // on créé un tableau contenant toutes les informations du semis

	// récupération des informations du semis
	$query_recuperation_semis = "SELECT se.QUANTITEGRAINESSEMIS AS quantite, se.REFERENCESEMIS AS reference, se.DATESEMIS AS plantation, t.CODETAXON AS idTaxon, f.NOMFAMILLE AS famille, g.NOMGENRE AS genre, e.NOMESPECE AS espece, v.NOMVARIETE AS variete, se.COMMENTAIRE AS commentaire, tou.CODETOUFFE AS idTouffe, tou.REFERENCETOUFFE refTouffe, trans.DATEENTREE AS dateTouffe ";
	$query_recuperation_semis .= "FROM semis se ";
	$query_recuperation_semis .= "INNER JOIN taxon t ON t.CODETAXON = se.CODETAXON ";
	$query_recuperation_semis .= "LEFT JOIN est_de_famille l1 INNER JOIN famille f ON f.CODEFAMILLE = l1.CODEFAMILLE ON l1.CODETAXON = t.CODETAXON AND l1.CODECLASSIFICATION = t.CODECLASSIFICATION ";
	$query_recuperation_semis .= "LEFT JOIN appartient_a_genre l2 INNER JOIN genre g ON g.CODEGENRE = l2.CODEGENRE ON l2.CODETAXON = t.CODETAXON AND l2.CODECLASSIFICATION = t.CODECLASSIFICATION ";
	$query_recuperation_semis .= "LEFT JOIN est_de_espece l3 INNER JOIN espece e ON e.CODEESPECE = l3.CODEESPECE ON l3.CODETAXON = t.CODETAXON AND l3.CODECLASSIFICATION = t.CODECLASSIFICATION ";
	$query_recuperation_semis .= "LEFT JOIN a_comme_variete l4 INNER JOIN variete v ON v.CODEVARIETE = l4.CODEVARIETE ON l4.CODETAXON = t.CODETAXON AND l4.CODECLASSIFICATION = t.CODECLASSIFICATION ";
	$query_recuperation_semis .= "LEFT JOIN entree trans INNER JOIN touffe tou ON tou.CODETOUFFE = trans.TOU_CODETOUFFE ON trans.CODESEMIS = se.CODESEMIS ";
	$query_recuperation_semis .= "WHERE se.CODESEMIS = ".$_GET['id']." ";
	$query_recuperation_semis .= "ORDER BY dateTouffe ";
	
	$result_recuperation_semis = mysql_query($query_recuperation_semis, $connexion) or logError("RECUPERATION SEMIS-".$query_recuperation_semis."-".mysql_error());
	
	while($tab_recuperation_semis = mysql_fetch_assoc($result_recuperation_semis)){
		
		$semis['quantite'] = $tab_recuperation_semis['quantite'];
		$semis['reference'] = $tab_recuperation_semis['reference'];
		$semis['plantation'] = $tab_recuperation_semis['plantation'];
		$semis['taxon']['id'] = $tab_recuperation_semis['idTaxon'];
		$semis['taxon']['famille'] = $tab_recuperation_semis['famille'];
		$semis['taxon']['genre'] = $tab_recuperation_semis['genre'];
		$semis['taxon']['espece'] = $tab_recuperation_semis['espece'];
		$semis['taxon']['variete'] = $tab_recuperation_semis['variete'];
		$semis['commentaire'] = $tab_recuperation_semis['commentaire'];
		
		if(!is_null($tab_recuperation_semis['idTouffe'])){
			$semis['transplantations'][$tab_recuperation_semis['idTouffe']]['id'] = $tab_recuperation_semis['idTouffe'];
			$semis['transplantations'][$tab_recuperation_semis['idTouffe']]['reference'] = $tab_recuperation_semis['refTouffe'];
			$semis['transplantations'][$tab_recuperation_semis['idTouffe']]['date'] = $tab_recuperation_semis['dateTouffe'];
		}
	
	}
	
	mysql_free_result($result_recuperation_semis);
	
	// récupération des entrées du semis
	$query_recuperation_entrees = "SELECT en.CODEENTREE AS idEntree, en.DATEENTREE AS dateEntree, en.NUMENTREE AS numEntree, en.NUMIPEN AS ipen, vn.CODEVISITEDANSNATURE AS idVisite, vn.DATEVISITE AS dateVisite, co.NOMCOMMUNE AS communeVisite, co.CODEPOSTAL AS cpVisite, ed.NOMTYPEENTREEDIVERSE AS entreeDiverse, sa.CODESACHETGRAINE AS idSachet, sa.REFERENCESACHETGRAINES AS refSachet, pee.CODEPERSONNE AS idPersonneEntree, pee.NOMPERSONNE AS nomPersonneEntree, pee.PRENOMPERSONNE AS prenomPersonneEntree, cmi.CODECOMMANDEINTERNE AS idCommandeEntree, cmi.DATECOMMANDE AS dateCommandeEntree, stcmi.NOMSTRUCTURE AS structureCommandeEntree, pre.CODEPRETENTRANT AS idPretEntree, stpre.NOMSTRUCTURE AS structurePretEntree, retprs.CODEPRETSORTANT AS idPretRetourSortie, stretprs.NOMSTRUCTURE AS structurePretRetourSortie, ste.CODESTRUCTURE AS idStructureEntree, ste.NOMSTRUCTURE AS structureEntree ";
	$query_recuperation_entrees .= "FROM entree en ";
	$query_recuperation_entrees .= "LEFT JOIN visite_dans_nature vn ON vn.CODEVISITEDANSNATURE = en.CODEVISITEDANSNATURE ";
	$query_recuperation_entrees .= "LEFT JOIN commune co ON co.CODECOMMUNE = vn.CODECOMMUNE ";
	$query_recuperation_entrees .= "LEFT JOIN type_entree_diverse ed ON ed.CODETYPEENTREEDIVERSE = en.CODETYPEENTREEDIVERSE ";
	$query_recuperation_entrees .= "LEFT JOIN sachet_graines sa ON sa.CODESACHETGRAINE = en.CODESACHETGRAINE ";
	$query_recuperation_entrees .= "LEFT JOIN personne pee ON pee.CODEPERSONNE = en.CODEPERSONNE ";
	$query_recuperation_entrees .= "LEFT JOIN ligne_livraison ll ON ll.CODELIGNELIVRAISON = en.CODELIGNELIVRAISON ";
	$query_recuperation_entrees .= "LEFT JOIN livraison lv ON lv.CODELIVRAISON = ll.CODELIVRAISON ";
	$query_recuperation_entrees .= "LEFT JOIN commande_interne cmi ON cmi.CODECOMMANDEINTERNE = lv.CODECOMMANDEINTERNE ";
	$query_recuperation_entrees .= "LEFT JOIN structure stcmi ON stcmi.CODESTRUCTURE = cmi.CODESTRUCTURE ";
	$query_recuperation_entrees .= "LEFT JOIN pret_entrant pre ON pre.CODEPRETENTRANT = en.CODEPRETENTRANT ";
	$query_recuperation_entrees .= "LEFT JOIN structure stpre ON stpre.CODESTRUCTURE = pre.CODESTRUCTURE ";
	$query_recuperation_entrees .= "LEFT JOIN pret_sortant retprs ON retprs.CODEPRETSORTANT = en.CODEPRETSORTANT ";
	$query_recuperation_entrees .= "LEFT JOIN structure stretprs ON retprs.CODESTRUCTURE = stretprs.CODESTRUCTURE ";
	$query_recuperation_entrees .= "LEFT JOIN structure ste ON ste.CODESTRUCTURE = en.CODESTRUCTURE ";
	$query_recuperation_entrees .= "WHERE en.SEM_CODESEMIS = ".$_GET['id']." ";
	$query_recuperation_entrees .= "ORDER BY dateEntree DESC ";
	
	$result_recuperation_entrees = mysql_query($query_recuperation_entrees, $connexion) or logError("RECUPERATION SEMIS-".$query_recuperation_entrees."-".mysql_error());
	
	$semis['ipen'] = null;
	while($tab_recuperation_entrees = mysql_fetch_assoc($result_recuperation_entrees)){
		
		if(!is_null($tab_recuperation_entrees['ipen'])){
			$semis['ipen'] = $tab_recuperation_entrees['ipen'];
		}
		
		$semis['entrees'][$tab_recuperation_entrees['idEntree']]['date'] = $tab_recuperation_entrees['dateEntree'];
		$semis['entrees'][$tab_recuperation_entrees['idEntree']]['numero'] = $tab_recuperation_entrees['numEntree'];
	
		if(!is_null($tab_recuperation_entrees['idVisite'])){
			$semis['entrees'][$tab_recuperation_entrees['idEntree']]['visite']['id'] = $tab_recuperation_entrees['idVisite'];
			$semis['entrees'][$tab_recuperation_entrees['idEntree']]['visite']['date'] = $tab_recuperation_entrees['dateVisite'];
			$semis['entrees'][$tab_recuperation_entrees['idEntree']]['visite']['commune'] = $tab_recuperation_entrees['communeVisite'];
		}
		if(!is_null($tab_recuperation_entrees['entreeDiverse'])){
			$semis['entrees'][$tab_recuperation_entrees['idEntree']]['divers'] = $tab_recuperation_entrees['entreeDiverse'];
		}
		if(!is_null($tab_recuperation_entrees['idSachet'])){
			$semis['entrees'][$tab_recuperation_entrees['idEntree']]['sachet']['id'] = $tab_recuperation_entrees['idSachet'];
			$semis['entrees'][$tab_recuperation_entrees['idEntree']]['sachet']['reference'] = $tab_recuperation_entrees['refSachet'];
		}
		if(!is_null($tab_recuperation_entrees['idPersonneEntree'])){
			$semis['entrees'][$tab_recuperation_entrees['idEntree']]['personne']['id'] = $tab_recuperation_entrees['idPersonneEntree'];
			$semis['entrees'][$tab_recuperation_entrees['idEntree']]['personne']['nom'] = $tab_recuperation_entrees['nomPersonneEntree'];
			$semis['entrees'][$tab_recuperation_entrees['idEntree']]['personne']['prenom'] = $tab_recuperation_entrees['prenomPersonneEntree'];
		}
		if(!is_null($tab_recuperation_entrees['idCommandeEntree'])){
			$semis['entrees'][$tab_recuperation_entrees['idEntree']]['commande']['id'] = $tab_recuperation_entrees['idCommandeEntree'];
			$semis['entrees'][$tab_recuperation_entrees['idEntree']]['commande']['date'] = $tab_recuperation_entrees['dateCommandeEntree'];
			$semis['entrees'][$tab_recuperation_entrees['idEntree']]['commande']['structure'] = $tab_recuperation_entrees['structureCommandeEntree'];
		}
		if(!is_null($tab_recuperation_entrees['idPretEntree'])){
			$semis['entrees'][$tab_recuperation_entrees['idEntree']]['pret']['id'] = $tab_recuperation_entrees['idPretEntree'];
			$semis['entrees'][$tab_recuperation_entrees['idEntree']]['pret']['structure'] = $tab_recuperation_entrees['structurePretEntree'];
		}
		if(!is_null($tab_recuperation_entrees['idPretRetourSortie'])){
			$semis['entrees'][$tab_recuperation_entrees['idEntree']]['retour']['id'] = $tab_recuperation_entrees['idPretRetourSortie'];
			$semis['entrees'][$tab_recuperation_entrees['idEntree']]['retour']['structure'] = $tab_recuperation_entrees['structurePretRetourSortie'];
		}
		if(!is_null($tab_recuperation_entrees['idStructureEntree'])){
			$semis['entrees'][$tab_recuperation_entrees['idEntree']]['structure']['id'] = $tab_recuperation_entrees['idStructureEntree'];
			$semis['entrees'][$tab_recuperation_entrees['idEntree']]['structure']['nom'] = $tab_recuperation_entrees['structureEntree'];
		}
	
	}
	
	mysql_free_result($result_recuperation_entrees);
	
	// récupération des sorties du semis
	$query_recuperation_sorties = "SELECT so.CODESORTIE AS idSortie, so.DATESORTIE AS dateSortie, so.NUMSORTIE AS numSortie, td.NOMTYPEDISPARITION AS disparition, prs.CODEPRETSORTANT AS idPretSortie, stprs.NOMSTRUCTURE AS structurePretSortie, retpre.CODEPRETENTRANT AS idPretRetourEntree, stretpre.NOMSTRUCTURE AS structurePretRetourEntree, cme.CODECOMMANDEEXTERNE AS idCommandeSortie, stcme.NOMSTRUCTURE AS structureCommandeSortie, pes.CODEPERSONNE AS idPersonneSortie, pes.NOMPERSONNE AS nomPersonneSortie, pes.PRENOMPERSONNE AS prenomPersonneSortie, sts.CODESTRUCTURE AS idStructureSortie, sts.NOMSTRUCTURE AS structureSortie ";
	$query_recuperation_sorties .= "FROM sortie so ";
	$query_recuperation_sorties .= "LEFT JOIN type_disparition td ON td.CODETYPEDISPARITION = so.CODETYPEDISPARITION ";
	$query_recuperation_sorties .= "LEFT JOIN pret_sortant prs ON prs.CODEPRETSORTANT = so.CODEPRETSORTANT ";
	$query_recuperation_sorties .= "LEFT JOIN structure stprs ON stprs.CODESTRUCTURE = prs.CODESTRUCTURE ";
	$query_recuperation_sorties .= "LEFT JOIN pret_entrant retpre ON retpre.CODEPRETENTRANT = so.CODEPRETENTRANT ";
	$query_recuperation_sorties .= "LEFT JOIN structure stretpre ON retpre.CODESTRUCTURE = stretpre.CODESTRUCTURE ";
	$query_recuperation_sorties .= "LEFT JOIN commande_externe cme ON cme.CODECOMMANDEEXTERNE = so.CODECOMMANDEEXTERNE ";
	$query_recuperation_sorties .= "LEFT JOIN structure stcme ON stcme.CODESTRUCTURE = cme.CODESTRUCTURE ";
	$query_recuperation_sorties .= "LEFT JOIN personne pes ON pes.CODEPERSONNE = so.CODEPERSONNE ";
	$query_recuperation_sorties .= "LEFT JOIN structure sts ON sts.CODESTRUCTURE = so.CODESTRUCTURE ";
	$query_recuperation_sorties .= "WHERE so.CODESEMIS = ".$_GET['id']." ";
	$query_recuperation_sorties .= "ORDER BY dateSortie DESC ";
	
	$result_recuperation_sorties = mysql_query($query_recuperation_sorties, $connexion) or logError("RECUPERATION SEMIS-".$query_recuperation_sorties."-".mysql_error());
	
	$semis['sorties'] = array();
	while($tab_recuperation_sorties = mysql_fetch_assoc($result_recuperation_sorties)){
		
		$semis['sorties'][$tab_recuperation_sorties['idSortie']]['date'] = $tab_recuperation_sorties['dateSortie'];
		$semis['sorties'][$tab_recuperation_sorties['idSortie']]['numero'] = $tab_recuperation_sorties['numSortie'];
	
		if(!is_null($tab_recuperation_sorties['disparition'])){
			$semis['sorties'][$tab_recuperation_sorties['idSortie']]['disparition'] = $tab_recuperation_sorties['disparition'];
		}
		if(!is_null($tab_recuperation_sorties['idPretSortie'])){
			$semis['sorties'][$tab_recuperation_sorties['idSortie']]['pret']['id'] = $tab_recuperation_sorties['idPretSortie'];
			$semis['sorties'][$tab_recuperation_sorties['idSortie']]['pret']['structure'] = $tab_recuperation_sorties['structurePretSortie'];
		}
		if(!is_null($tab_recuperation_sorties['idPretRetourEntree'])){
			$semis['sorties'][$tab_recuperation_sorties['idSortie']]['retour']['id'] = $tab_recuperation_sorties['idPretRetourEntree'];
			$semis['sorties'][$tab_recuperation_sorties['idSortie']]['retour']['structure'] = $tab_recuperation_sorties['structurePretRetourEntree'];
		}
		if(!is_null($tab_recuperation_sorties['idCommandeSortie'])){
			$semis['sorties'][$tab_recuperation_sorties['idSortie']]['commande']['id'] = $tab_recuperation_sorties['idCommandeSortie'];
			$semis['sorties'][$tab_recuperation_sorties['idSortie']]['commande']['structure'] = $tab_recuperation_sorties['structureCommandeSortie'];
		}
		if(!is_null($tab_recuperation_sorties['idPersonneSortie'])){
			$semis['sorties'][$tab_recuperation_sorties['idSortie']]['personne']['id'] = $tab_recuperation_sorties['idPersonneSortie'];
			$semis['sorties'][$tab_recuperation_sorties['idSortie']]['personne']['nom'] = $tab_recuperation_sorties['nomPersonneSortie'];
			$semis['sorties'][$tab_recuperation_sorties['idSortie']]['personne']['prenom'] = $tab_recuperation_sorties['prenomPersonneSortie'];
		}
		if(!is_null($tab_recuperation_sorties['idStructureSortie'])){
			$semis['sorties'][$tab_recuperation_sorties['idSortie']]['structure']['id'] = $tab_recuperation_sorties['idStructureSortie'];
			$semis['sorties'][$tab_recuperation_sorties['idSortie']]['structure']['nom'] = $tab_recuperation_sorties['structureSortie'];
		}
	
	}
	
	mysql_free_result($result_recuperation_sorties);
	
?>
<h3>Détail d'un semis</h3>
<table class="fiche" style="width: 100%;">
	<tr>
		<td style="width: 20%" class="etiquette">Taxon:</td>
		<td style="width: 80%"><?php echo "<a href=\"popup.php?p=gestion/taxon_affiche_popup&amp;id=".$semis['taxon']['id']."\" onclick=\"popup(this.href, 640, 480); return false;\"><b>".htmlentities(capitalise($semis['taxon']['famille']), ENT_NOQUOTES, "UTF-8")." ".htmlentities(capitalise($semis['taxon']['genre']), ENT_NOQUOTES, "UTF-8")." ".htmlentities(capitalise($semis['taxon']['espece']), ENT_NOQUOTES, "UTF-8")." ".htmlentities(capitalise($semis['taxon']['variete']), ENT_NOQUOTES, "UTF-8")."</b></a>"; ?></td>
	</tr>
	<tr>
		<td class="etiquette">N° entrée:</td>
		<td>
			<?php 
				if(!is_null($semis['reference'])){
					echo htmlentities($semis['reference'], ENT_NOQUOTES, "UTF-8");
				}else{
					echo "<i>aucune</i>";
				}
			?>
		</td>
	</tr>
	<tr>
		<td class="etiquette">N° IPEN:</td>
		<td>
			<?php 
				if(!is_null($semis['ipen'])){
					echo htmlentities($semis['ipen'], ENT_NOQUOTES, "UTF-8");
				}else{
					echo "<i>inconnu</i>";
				}
			?>
		</td>
	</tr>
	<tr>
		<th colspan="2">Statut</th>
	</tr>
	<tr>
		<td class="etiquette">Actuellement:</td>
		<td>
			<?php 
				if(!isset($semis['touffe'])){
					if(count($semis['entrees']) > count($semis['sorties'])){
						echo "<span style=\"font-weight: bold; color: #00AA00;\">au jardin</span>";
					}else{
						echo "<span style=\"font-weight: bold; color: #FF0000;\">sorti</span>";
					}
				}else{
					echo "<span style=\"font-weight: bold; color: #00AAFF;\">transplanté</span> : Le ".dateFr($semis['touffe']['date'])." - <a href=\"popup.php?p=gestion/touffe_affiche_popup&amp;id=".$semis['touffe']['id']."\" onclick=\"popup(this.href, 640, 480); return false;\">";
					echo "touffe";
					if(!is_null($semis['touffe']['reference'])){
						echo " (n° ent. ".htmlentities($semis['touffe']['reference'], ENT_NOQUOTES, "UTF-8").")";
					}
					echo "</a>";
					echo "</span>";
				}
			?>
		</td>
	</tr>
	<tr>
		<td class="etiquette">Contenu:</td>
		<td>
			<?php 
				if(!is_null($semis['quantite'])){
					if($semis['quantite'] > 0){
						echo "<span style=\"font-weight: bold; color: #00AA00;\">".$semis['quantite']." graine(s) encore plantée(s)</span>";
					}else{
						echo "<span style=\"font-weight: bold; color: #FF0000;\">entièrement transplanté</span>";
					}
				}else{
					echo "<i>non-indiquées</i>";
				}
			?>
		</td>
	</tr>
	<tr>
		<td class="etiquette">Transplantation:</td>
		<td>
			<?php 
				if(isset($semis['transplantations'])){
					echo "<ul>";
					foreach($semis['transplantations'] as $transplantations){
						echo "<li>";
						echo "Le ".dateFr($transplantations['date'])." - <a href=\"popup.php?p=gestion/touffe_affiche_popup&amp;id=".$transplantations['id']."\" onclick=\"popup(this.href, 640, 480); return false;\">";
						echo "touffe";
						if(!is_null($transplantations['reference'])){
							echo " (n° ent. ".htmlentities($transplantations['reference'], ENT_NOQUOTES, "UTF-8").")";
						}
						echo "</a>";
						echo "</li>";
					}
					unset($transplantations);
					echo "</ul>";
				}else{
					echo "<i>aucune</i>";
				}
			?>
		</td>
	</tr>
	<tr>
		<th colspan="2">Historique</th>
	</tr>
	<tr>
		<td class="etiquette">Entrées:</td>
		<td>
			<ul>
				<?php 
					foreach($semis['entrees'] as $entree){
						echo "<li>";
						echo "<span class=\"souligne\"><b>".dateFr($entree['date'])."</b>";
						if(!is_null($entree['numero'])){
							echo " (n° ".htmlentities($entree['numero'], ENT_NOQUOTES, "UTF-8").")";
						}
						echo " :</span> ";
						
						if(isset($entree['visite'])){
							echo " récolté à ".htmlentities(capitalise($entree['visite']['commune']), ENT_NOQUOTES, "UTF-8").", le ".dateFr($entree['visite']['date'])." [<a href=\"popup.php?p=gestion/visitedansnature_affiche_popup&amp;id=".$entree['visite']['id']."\" onclick=\"popup(this.href, 680, 500); return false;\">visite</a>]";
						}
						if(isset($entree['divers'])){
							echo " ".htmlentities($entree['divers'], ENT_NOQUOTES, "UTF-8")." (<i>entrée diverse</i>)";
						}
						if(isset($entree['sachet'])){
							echo " planté d'un <a href=\"popup.php?p=gestion/sachetgraines_affiche_popup&amp;id=".$entree['sachet']['id']."\" onclick=\"popup(this.href, 640, 480); return false;\">sachet de graines";
							if(!is_null($entree['sachet']['reference'])){
								echo " (n° ent. ".htmlentities($entree['sachet']['reference'], ENT_NOQUOTES, "UTF-8").")";
							}
							echo "</a>";
						}
						if(isset($entree['personne'])){
							echo " donné par <a href=\"popup.php?p=gestion/personne_affiche_popup&amp;id=".$entree['personne']['id']."\" onclick=\"popup(this.href, 350, 400); return false;\">".htmlentities(capitalise($entree['personne']['prenom']), ENT_NOQUOTES, "UTF-8")." ".htmlentities(mb_strtoupper($entree['personne']['nom']), ENT_NOQUOTES, "UTF-8")."</a>";
						}
						if(isset($entree['commande'])){
							echo " commandé à ".htmlentities($entree['commande']['structure'], ENT_NOQUOTES, "UTF-8").", le ".dateFr($entree['commande']['date'])." [<a href=\"popup.php?p=gestion/commandeinterne_affiche_popup&amp;id=".$entree['commande']['id']."\" onclick=\"popup(this.href, 680, 500); return false;\">commande</a>]";
						}
						if(isset($entree['pret'])){
							echo " emprunté à ".htmlentities($entree['pret']['structure'], ENT_NOQUOTES, "UTF-8")." [<a href=\"popup.php?p=gestion/pretentrant_affiche_popup&amp;id=".$entree['pret']['id']."\" onclick=\"popup(this.href, 500, 400); return false;\">prêt</a>]";
						}
						if(isset($entree['retour'])){
							echo " retour du prêt à ".htmlentities($entree['retour']['structure'], ENT_NOQUOTES, "UTF-8")." [<a href=\"popup.php?p=gestion/pretsortant_affiche_popup&amp;id=".$entree['retour']['id']."\" onclick=\"popup(this.href, 500, 400); return false;\">prêt</a>]";
						}
						if(isset($entree['structure'])){
							echo " donné par <a href=\"popup.php?p=gestion/structure_affiche_popup&amp;id=".$entree['structure']['id']."\" onclick=\"popup(this.href, 400, 500); return false;\">".htmlentities($entree['structure']['nom'], ENT_NOQUOTES, "UTF-8")."</a>";
						}
						
						echo "</li>";
					}
					unset($entree);
				?>
			</ul>
		</td>
	</tr>
	<tr>
		<td class="etiquette">Sorties:</td>
		<td>
			<?php
				if(count($semis['sorties']) > 0){
					echo "<ul>";
					foreach($semis['sorties'] as $sortie){
						echo "<li>";
						echo "<span class=\"souligne\"><b>".dateFr($sortie['date'])."</b>";
						if(!is_null($sortie['numero'])){
							echo " (n° ".htmlentities($sortie['numero'], ENT_NOQUOTES, "UTF-8").")";
						}
						echo " :</span>";
						
						if(isset($sortie['disparition'])){
							echo " ".htmlentities($sortie['disparition'], ENT_NOQUOTES, "UTF-8")." (<i>disparition</i>)";
						}
						if(isset($sortie['personne'])){
							echo " donné à <a href=\"popup.php?p=gestion/personne_affiche_popup&amp;id=".$sortie['personne']['id']."\" onclick=\"popup(this.href, 350, 400); return false;\">".htmlentities(capitalise($sortie['personne']['prenom']), ENT_NOQUOTES, "UTF-8")." ".htmlentities(mb_strtoupper($sortie['personne']['nom']), ENT_NOQUOTES, "UTF-8")."</a>";
						}
						if(isset($sortie['commande'])){
							echo " envoyé à ".htmlentities($sortie['commande']['structure'], ENT_NOQUOTES, "UTF-8")." [<a href=\"popup.php?p=gestion/commandeexterne_affiche_popup&amp;id=".$sortie['commande']['id']."\" onclick=\"popup(this.href, 680, 500); return false;\">requête</a>]";
						}
						if(isset($sortie['pret'])){
							echo " prêté à ".htmlentities($sortie['pret']['structure'], ENT_NOQUOTES, "UTF-8")." [<a href=\"popup.php?p=gestion/pretsortant_affiche_popup&amp;id=".$sortie['pret']['id']."\" onclick=\"popup(this.href, 500, 400); return false;\">prêt</a>]";
						}
						if(isset($sortie['retour'])){
							echo " retour du prêt de ".htmlentities($sortie['retour']['structure'], ENT_NOQUOTES, "UTF-8")." [<a href=\"popup.php?p=gestion/pretsortant_affiche_popup&amp;id=".$sortie['retour']['id']."\" onclick=\"popup(this.href, 500, 400); return false;\">prêt</a>]";
						}
						if(isset($sortie['structure'])){
							echo " donné à <a href=\"popup.php?p=gestion/structure_affiche_popup&amp;id=".$sortie['structure']['id']."\" onclick=\"popup(this.href, 400, 500); return false;\">".htmlentities($sortie['structure']['nom'], ENT_NOQUOTES, "UTF-8")."</a>";
						}
						
						echo "</li>";
					}
					unset($sortie);
					echo "</ul>";
				}else{
					echo "<i>aucune</i>";
				}
			?>
		</td>
	</tr>
	<tr>
		<th colspan="2">Commentaire</th>
	</tr>
	<tr>
		<td class="texte" colspan="2"><?php echo nl2br(htmlentities($semis['commentaire'], ENT_NOQUOTES, "UTF-8")); ?></td>
	</tr>
</table>
<?php
//------------------------------------------------------------ Accès refusé à la page

			}else{
				afficherStatut("Le semis n'existe pas", 3); // appel à la fonction afficherStatut() définie dans fonctions.php
			}

		}else{
			afficherStatut("Le semis n'est pas ou mal indiqué", 3); // appel à la fonction afficherStatut() définie dans fonctions.php
		}

	}else{
		if(isset($_SESSION)){
			include("pages/401.htm");
		}
	}

?>